package com.example.myshools.Mine.student.edit;


import android.Manifest;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.myshools.Mine.organization.publish.IdentificationResult;
import com.example.myshools.R;
import com.example.myshools.entity.Constant;
import com.example.myshools.entity.Student;
import com.example.myshools.util.GlideEngine;
import com.example.myshools.util.InputTextDialog;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.language.LanguageConfig;
import com.luck.picture.lib.listener.OnResultCallbackListener;
import com.luck.picture.lib.style.PictureWindowAnimationStyle;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class StudentData extends AppCompatActivity implements View.OnClickListener {
    private TextView s_img_upload_tip;//修改头像
    private TextView s_name_tip;//名字
    private TextView s_nickname_tip;//昵称
    private TextView s_number_tip;//学号
    private TextView s_college_tip;//学院
    private TextView s_information_tip;//资料简介
    private TextView s_ren_zh_1_tip;//认证图片正面
    private TextView s_ren_zh_2_tip;//认证图片反面

    private TextView s_name;
    private TextView s_nickname;
    private TextView s_number;
    private TextView s_college;
    private TextView s_information;

    private TextView read_provide;//上传规范

    private ImageView s_img;//头像
    private ImageView s_ren_z1;//正面
    private ImageView s_ren_z2;//反面

    private Button up_data;
    private Button return_mine;
    private Student student;

    private Boolean renZStatues = false;//默认为false，修改认证资料的时候设为true
    private Boolean nameStatus = false;
    private Boolean numberStatus = false;
    private Boolean collegeStatus = false;


    private PictureWindowAnimationStyle mWindowAnimationStyle;//相册启动动画
    private List<LocalMedia> result = new ArrayList<>();
    private InputTextDialog inputTextDialog;//文字输入框
    private OkHttpClient okHttpClient = new OkHttpClient();
    private int id;//userId
    private ImageView now;
    private Boolean nowStatus;
    private int who;


    private int result0;//数据库更改返回的值


    private Boolean isUpdate=false;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mine_student_data);

        String s = getIntent().getStringExtra("s");
        Gson gson = new Gson();
        student = gson.fromJson(s, Student.class);
        id = student.getId();
        if (Build.VERSION.SDK_INT >= 23) {
            String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CALL_PHONE, Manifest.permission.READ_LOGS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SET_DEBUG_APP, Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_APN_SETTINGS};
            ActivityCompat.requestPermissions(this, mPermissionList, 123);
        }
        findView();
        setView();
        setListener();
    }


    private void findView() {

        read_provide=findViewById(R.id.read_provide);

        s_img = findViewById(R.id.s_img);//头像
        return_mine = findViewById(R.id.btn_return_setting);//返回
        s_name = findViewById(R.id.s_name);//名字
        s_nickname = findViewById(R.id.s_nickname);//昵称
        s_number = findViewById(R.id.s_number);//学号
        s_college = findViewById(R.id.s_college);//学院
        s_information = findViewById(R.id.s_information);//介绍

        up_data = findViewById(R.id.s_up_data);//验证
        up_data.setEnabled(false);//初始化时使验证按钮不可点击
        s_ren_z1 = findViewById(R.id.s_ren_z1);//正面图
        s_ren_z2 = findViewById(R.id.s_ren_z2);//反面图

        s_img_upload_tip = findViewById(R.id.s_img_upload_tip); //头像修改成功后显示
        s_name_tip = findViewById(R.id.s_up_name_tip);//名字修改成功后显示
        s_nickname_tip = findViewById(R.id.s_up_nickname_tip);//昵称修改成功后显示
        s_number_tip = findViewById(R.id.s_up_number_tip);//学号修改成功后显示
        s_college_tip = findViewById(R.id.s_up_college_tip);//学院修改成功后显示
        s_information_tip = findViewById(R.id.s_information_upload_tip); //修改资料成功后显示
        s_ren_zh_1_tip = findViewById(R.id.s_ren_zh_1_tip);  //认证图片正面
        s_ren_zh_2_tip = findViewById(R.id.s_ren_zh_2_tip);  //认证图片反面


    }


    private void setView() {
        s_name.setText(student.getStuName());
        s_nickname.setText(student.getStuNickName());
        s_college.setText(student.getCollege());
        s_number.setText(student.getStuNumber());
        s_information.setText(student.getRecommend());


        //开启线程加载图片
        Message message00 = new Message();
        message00.what = 100;
        handler.sendMessage(message00);
        Message message11 = new Message();
        message11.what = 101;
        handler.sendMessage(message11);
        Message message22 = new Message();
        message22.what = 102;
        handler.sendMessage(message22);

    }


    private void setListener() {
        //返回
        return_mine.setOnClickListener(this::onClick);
        //名字修改
        s_name.setOnClickListener(this::onClick);
        //学号修改
        s_number.setOnClickListener(this::onClick);
        //学院修改
        s_college.setOnClickListener(this::onClick);
        //昵称修改
        s_nickname.setOnClickListener(this::onClick);
        //头像点击修改：
        s_img.setOnClickListener(this::onClick);
        //资料简介修改
        s_information.setOnClickListener(this::onClick);

        //认证图片修改
        s_ren_z1.setOnClickListener(this::onClick);
        s_ren_z2.setOnClickListener(this::onClick);
        //开始认证
        up_data.setOnClickListener(this::onClick);
        //阅读认证规范
        read_provide.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.s_img:
                //打开图片选择器
                s_img_upload_tip.setText("");
                now = s_img;
                nowStatus = true;
                who = 1;
                openPictureSelect();
                break;
            case R.id.s_ren_z1:
                //修改认证图片
                s_ren_zh_1_tip.setText("");
                who = 2;
                now = s_ren_z1;
                nowStatus = false;//不开启裁剪
                openPictureSelect();
                break;
            case R.id.s_ren_z2:
                //修改认证图片
                s_ren_zh_2_tip.setText("");
                who = 3;
                now = s_ren_z2;
                nowStatus = false;//不开启裁剪
                openPictureSelect();
                break;
            case R.id.btn_return_setting:
                //EventBus.getDefault().post(new Message());
                finish();
                break;

            case R.id.s_nickname:
                s_nickname_tip.setText("");
                inputTextDialog = new InputTextDialog(StudentData.this, R.style.dialog_center, 8);
                String hint = "";
                if (s_nickname.getText().toString().length() > 0) {
                    hint = s_nickname.getText().toString();
                } else {
                    hint = "请输入昵称";
                }
                inputTextDialog.setHint(hint);
                inputTextDialog.setMaxNumber(8);
                inputTextDialog.show();
                inputTextDialog.setmOnTextSendListener(msg -> {
                    s_nickname.setText(msg);
                    //数据库修改
                    updateStuNickName(msg);
                });

                break;
            case R.id.s_name:
                s_name_tip.setText("");
                inputTextDialog = new InputTextDialog(StudentData.this, R.style.dialog_center, 20);
                String hint1 = "";
                if (s_name.getText().toString().length() > 0) {
                    hint1 = s_name.getText().toString();
                } else {
                    hint1 = "请输入名字";
                }
                inputTextDialog.setHint(hint1);
                inputTextDialog.setMaxNumber(20);//最长十个字
                inputTextDialog.show();
                inputTextDialog.setmOnTextSendListener(msg -> {
                    s_name.setText(msg);
                    //数据库修改
                    updateStuName(msg);
                });
                break;
            case R.id.s_number:
                s_number_tip.setText("");
                inputTextDialog = new InputTextDialog(StudentData.this, R.style.dialog_center, 20);
                String hint2 = "";
                if (s_number.getText().toString().length() > 0) {
                    hint2 = s_number.getText().toString();
                } else {
                    hint2 = "请输入名字";
                }
                inputTextDialog.setHint(hint2);
                inputTextDialog.setMaxNumber(20);//最长十个字
                inputTextDialog.show();
                inputTextDialog.setmOnTextSendListener(msg -> {
                    s_number.setText(msg);
                    //数据库修改
                    updateStuNumber(msg);
                });
                break;
            case R.id.s_college:
                s_college_tip.setText("");
                inputTextDialog = new InputTextDialog(StudentData.this, R.style.dialog_center, 20);
                String hint4 = "";
                if (s_college.getText().toString().length() > 0) {
                    hint4 = s_college.getText().toString();
                } else {
                    hint4 = "";
                }
                inputTextDialog.setHint(hint4);
                inputTextDialog.setMaxNumber(200);
                inputTextDialog.show();
                inputTextDialog.setmOnTextSendListener(msg -> {
                    s_college.setText(msg);
                    //数据库修改
                    updateStuCollege(msg);
                });
                break;

            case R.id.s_information:
                s_information_tip.setText("");
                inputTextDialog = new InputTextDialog(StudentData.this, R.style.dialog_center, 200);
                String hint3 = "";
                if (s_information.getText().toString().length() > 0) {
                    hint3 = s_information.getText().toString();
                } else {
                    hint3 = "建议修改文本后复制粘贴到这里";
                }
                inputTextDialog.setHint(hint3);
                inputTextDialog.setMaxNumber(200);
                inputTextDialog.show();
                inputTextDialog.setmOnTextSendListener(msg -> {
                    s_information.setText(msg);
                    //数据库修改
                    updateInformation(msg);
                });
                break;

            //阅读认证规范文档
            case R.id.read_provide:

                break;

            case R.id.s_up_data:
                Boolean is=false;//判断，学生证是否重新上传，如果没有上传下一步判断之前有没有
                if(isUpdate){
                    is=true;
                }else {
                    if(student.getIdentityImgReverse()!=null || student.getIdentityImgObverse() !=null)
                    {
                        is=true;
                    }else {
                        is=false;
                    }
                }
                if(is&&student.getStuName().length()!=0 && student.getCollege().length()!=0&&student.getStuNumber().length()!=0){
                    //向服务器发送认证请求，将认证status设为2
                    up_data.setEnabled(false);
                    up_data.setBackgroundColor(Color.parseColor("#bfbfbf"));
                    up_data.setText("正在发送请求");
                    sendIdentityRequest(1,id);
                }else {
                    Toast.makeText(StudentData.this, "请完善信息后再认证", Toast.LENGTH_SHORT).show();
                }



        }

    }

    //图片选择，上传图片
    private void openPictureSelect() {
        Boolean j=false;
        if (nowStatus==true){
            j=false;
        }else {
            j=true;
        }
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())//相册 媒体类型 PictureMimeType.ofAll()、ofImage()、ofVideo()、ofAudio()
                //.openCamera()//单独使用相机 媒体类型 PictureMimeType.ofImage()、ofVideo()
                .theme(R.style.picture_default_style)// xml样式配制 R.style.picture_default_style、picture_WeChat_style or 更多参考Demo
                .loadImageEngine(GlideEngine.createGlideEngine())// 图片加载引擎 需要 implements ImageEngine接口
                .selectionMode(PictureConfig.SINGLE)//单选or多选 PictureConfig.SINGLE PictureConfig.MULTIPLE
                .isPageStrategy(false)//开启分页模式，默认开启另提供两个参数；pageSize每页总数；isFilterInvalidFile是否过滤损坏图片
                // .isSingleDirectReturn(true)//PictureConfig.SINGLE模式下是否直接返回
                // .isWeChatStyle()//开启R.style.picture_WeChat_style样式
                //.setPictureStyle()//动态自定义相册主题
                //.setPictureCropStyle()//动态自定义裁剪主题
                .setPictureWindowAnimationStyle(mWindowAnimationStyle)//相册启动退出动画
                .isCamera(false)//列表是否显示拍照按钮
                //.isZoomAnim(pi)//图片选择缩放效果
                // .imageFormat()//拍照图片格式后缀,默认jpeg, PictureMimeType.PNG，Android Q使用PictureMimeType.PNG_Q
                .maxSelectNum(1)//最大选择数量,默认9张
                .minSelectNum(1)// 最小选择数量
                .compress(true)//是否压缩
                .compressFocusAlpha(true)//压缩后是否保持图片的透明通道
                .minimumCompressSize(2)// 小于多少kb的图片不压缩
                .imageSpanCount(4)//列表每行显示个数
                .openClickSound(false)//是否开启点击声音

                .selectionMedia(result)//是否传入已选图片

                .previewImage(true)//是否预览图片
                .enableCrop(true)//是否开启裁剪
                .freeStyleCropEnabled(true)//裁剪框是否可拖拽
                .circleDimmedLayer(nowStatus)// 是否开启圆形裁剪
                .setCircleDimmedBorderColor(R.color.textColorBlue)//设置圆形裁剪边框色值
                .setCircleStrokeWidth(2)//设置圆形裁剪边框粗细
                .showCropFrame(j)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
                .showCropGrid(j)//是否显示裁剪矩形网格 圆形裁剪时建议设为false
                .rotateEnabled(true)//裁剪是否可旋转图片
                .scaleEnabled(true)//裁剪是否可放大缩小图片
                .isDragFrame(true)//是否可拖动裁剪框(固定)
                .hideBottomControls(false)//显示底部uCrop工具栏
                .cutOutQuality(70)//裁剪后输出质量，默认100

                .setLanguage(LanguageConfig.CHINESE)//国际化语言 LanguageConfig.CHINESE、ENGLISH、JAPAN等

                .isMaxSelectEnabledMask(true)//选择条件达到阀时列表是否启用蒙层效果
                .forResult(new MyResultCallback());//结果回调分两种方式onActivityResult()和OnResultCallbackListener方式
    }

    private class MyResultCallback implements OnResultCallbackListener<LocalMedia> {

        @Override
        public void onResult(List<LocalMedia> result1) {
            result = result1;
            //上传服务器
            Message message = new Message();
            message.what = 200;
            message.obj = result.get(0).getCompressPath();
            handler.sendMessage(message);
            upLoad();
        }

        @Override
        public void onCancel() {

        }
    }

    private void upLoad() {
        if (now == s_ren_z1) {
            s_ren_zh_1_tip.setText("正在上传");
        }
        if (now == s_ren_z2) {
            s_ren_zh_2_tip.setText("正在上传");
        }
        if (now == s_img) {
            s_img_upload_tip.setText("正在上传");
        }
        int role = 1;
        File file = new File(result.get(0).getCompressPath());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);//把文件与类型放入请求体
        MultipartBody.Builder builder = new MultipartBody.Builder();
        builder.setType(MultipartBody.FORM)
                .addFormDataPart("userId", String.valueOf(id)).addFormDataPart("role", String.valueOf(role)).addFormDataPart("who", String.valueOf(who));
        if (file.exists()) {
            builder.addFormDataPart("file", file.getName(), requestBody);//文件名,请求体里的文件
        }
        MultipartBody multipartBody = builder.build();

        Request request = new Request.Builder()
                .url(Constant.url + "photo/updateUserImgPath")
                .post(multipartBody)
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 1;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Log.e("jsonstrqqqqqqqqq", jsonStr);
                Gson gson = new Gson();
                Map map = new HashMap();
                map = gson.fromJson(jsonStr, new TypeToken<Map>() {
                }.getType());
                String res = map.get("result").toString();
                String w = map.get("who").toString();
                Message message = new Message();
                if (res.equals("ok")) {//更改返回结果表示ok为成功
                    message.what = 2;
                } else {
                    //更改失败
                    message.what = 404;
                }
                message.obj = w;
                handler.sendMessage(message);


            }
        });
    }

    //修改学生姓名
    private void updateStuName(String msg) {
        s_name_tip.setText("修改中..");
        FormBody.Builder builder = new FormBody.Builder().add("name", msg).add("id", String.valueOf(id));
        FormBody body = builder
                .build();
        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateStuNameById")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 3;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Message message = new Message();
                message.what = 4;
                message.obj = jsonStr;
                handler.sendMessage(message);
            }
        });
    }

    //修改学生介绍
    private void updateInformation(String msg) {
        s_information_tip.setText("修改中..");
        FormBody.Builder builder = new FormBody.Builder().add("commend", msg).add("id", String.valueOf(id));
        FormBody body = builder
                .build();

        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateStuRecommend")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 5;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Message message = new Message();
                message.what = 6;
                message.obj = jsonStr;
                handler.sendMessage(message);
            }
        });


    }

    //修改学生昵称
    private void updateStuNickName(String msg) {
        s_nickname_tip.setText("修改中..");
        FormBody.Builder builder = new FormBody.Builder().add("nickname", msg).add("id", String.valueOf(id));
        FormBody body = builder
                .build();
        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateStuNickNameById")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 7;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Message message = new Message();
                message.what = 8;
                message.obj = jsonStr;
                handler.sendMessage(message);
            }
        });
    }

    //修改学生学号
    private void updateStuNumber(String msg) {
        s_number_tip.setText("修改中..");
        FormBody.Builder builder = new FormBody.Builder().add("number", msg).add("id", String.valueOf(id));
        FormBody body = builder
                .build();
        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateStuNumberById")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 9;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Message message = new Message();
                message.what = 10;
                message.obj = jsonStr;
                handler.sendMessage(message);
            }
        });
    }
    //修改学生学院
    private void updateStuCollege(String msg) {
        s_college_tip.setText("修改中..");
        FormBody.Builder builder = new FormBody.Builder().add("college", msg).add("id", String.valueOf(id));
        FormBody body = builder
                .build();
        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateStuCollegeById")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = new Message();
                message.what = 11;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();
                Message message = new Message();
                message.what = 12;
                message.obj = jsonStr;
                handler.sendMessage(message);
            }
        });
    }


    //发送认证请求
    private void sendIdentityRequest(int role, int id) {
        FormBody.Builder builder = new FormBody.Builder().add("role", String.valueOf(role)).add("id", String.valueOf(id)).add("status", String.valueOf(2));
        FormBody body = builder
                .build();
        Request request = new Request.Builder()
                .post(body)
                .url(Constant.url + "user/updateIdentityById")
                .build();
        final Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message=new Message();
                message.what=13;
                handler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功 succeed ，，获取返回数据时 回调此方法
                String jsonStr = response.body().string();

                Message message = new Message();
                    message.what=14;
                    message.obj=jsonStr;
                 handler.sendMessage(message);


            }
        });

    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            //网络错误的原因
            if (msg.what == 1) {
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
            }
            //上传照片成功时
            if (msg.what == 2) {
                //上传成功
                if (msg.obj.toString().equals("one")) {
                    //头像
                    s_img_upload_tip.setText("成功");
                }
                if (msg.obj.toString().equals("two")) {
                    s_ren_zh_1_tip.setText("1:成功");
                    isUpdate=true;
                    up_data.setEnabled(true);
                    up_data.setBackgroundColor(Color.parseColor("#1296db"));
                    //正面
                }
                if (msg.obj.toString().equals("three")) {
                    s_ren_zh_2_tip.setText("2:成功");
                    up_data.setEnabled(true);
                    isUpdate=true;
                    up_data.setBackgroundColor(Color.parseColor("#1296db"));
                    //反面
                }
            }
            //修改名字
            if (msg.what == 3) {
                s_name_tip.setText("失败");
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
            }
            if (msg.what == 4) {
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    s_name_tip.setText("成功");
                    up_data.setEnabled(true);
                    up_data.setBackgroundColor(Color.parseColor("#1296db"));
                    student.setStuName(s_name.getText().toString());
                } else {
                    s_name_tip.setText("失败");
                }
            }
            //修改个人介绍
            if (msg.what == 5) {
                s_information_tip.setText("失败");
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
            }
            if (msg.what == 6) {
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    s_information_tip.setText("成功");
                    student.setRecommend(s_information.getText().toString());
                } else {
                    s_information_tip.setText("失败");
                }
            }
            //修改昵称
            if (msg.what == 7) {
                s_nickname_tip.setText("失败");
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
            }
            if (msg.what == 8) {
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    s_nickname_tip.setText("成功");
                    student.setStuNickName(s_nickname.getText().toString());
                } else {
                    s_nickname_tip.setText("失败");
                }
            }
            //修改学号
            if (msg.what == 9) {
                s_number_tip.setText("失败");
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
            }
            if (msg.what == 10) {
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    s_number_tip.setText("成功");
                    up_data.setEnabled(true);
                    up_data.setBackgroundColor(Color.parseColor("#1296db"));
                    student.setStuNumber(s_number.getText().toString());
                } else {
                    s_number_tip.setText("失败");
                }
            }
            //修改学院
            if (msg.what == 11) {
                s_college_tip.setText("失败");
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();

            }
            if (msg.what == 12) {
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    s_college_tip.setText("成功");
                    up_data.setEnabled(true);
                    up_data.setBackgroundColor(Color.parseColor("#1296db"));
                    student.setCollege(s_college.getText().toString());
                } else {
                    s_college_tip.setText("失败");
                }

            }


            //认证结果

            if(msg.what==13){
                Toast.makeText(StudentData.this, "网络错误，请检查网络", Toast.LENGTH_SHORT).show();
                up_data.setEnabled(true);
                up_data.setText("开始认证");
            }
            if(msg.what==14){
                String s = msg.obj.toString();
                if (s.equals("1")) {
                    Intent intent=new Intent(StudentData.this, IdentificationResult.class).putExtra("status",2);
                    startActivity(intent);
                   // EventBus.getDefault().post(new Message());
                    finish();
                } else {
                    Toast.makeText(StudentData.this, "连接错误，稍后重新认证", Toast.LENGTH_SHORT).show();
                    up_data.setEnabled(true);
                    up_data.setText("开始认证");
                }

            }

            //上传照片失败时
            if (msg.what == 404) {
                if (msg.obj.toString().equals("one")) {
                    //头像
                    s_img_upload_tip.setText("失败");
                }
                if (msg.obj.toString().equals("two")) {
                    s_ren_zh_1_tip.setText("1:失败");
                    //正面
                }
                if (msg.obj.toString().equals("three")) {
                    s_ren_zh_2_tip.setText("2:失败");
                }
                Toast.makeText(StudentData.this, "服务器出错正在维修，请稍后重试", Toast.LENGTH_SHORT).show();
            }

            //选择照片之后
            if (msg.what == 200) {
                if (now == s_img) {
                    RequestOptions requestOptions = new RequestOptions().circleCrop();
                    Glide.with(StudentData.this).load(msg.obj.toString()).apply(requestOptions).into(s_img);
                } else {
                    Glide.with(StudentData.this).load(msg.obj.toString()).into(now);
                }
            }

            //初始化页面时加载三个图片
            if (msg.what == 100) {
                if (student.getHeadPath() != null) {
                    RequestOptions requestOptions = new RequestOptions().placeholder(R.drawable.tou).fallback(R.drawable.tou).error(R.drawable.tou).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop();
                    Glide.with(StudentData.this).load(student.getHeadPath()).apply(requestOptions).into(s_img);
                }
            }
            if (msg.what == 101) {
                if (student.getIdentityImgObverse() != null) {
                    RequestOptions requestOptions1 = new RequestOptions().placeholder(R.drawable.onglide).fallback(R.drawable.onglide).error(R.drawable.error).diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter();
                    Glide.with(StudentData.this).load(student.getIdentityImgObverse()).apply(requestOptions1).into(s_ren_z1);
                }
            }
            if (msg.what == 102) {
                if (student.getIdentityImgReverse() != null) {
                    RequestOptions requestOptions2 = new RequestOptions().placeholder(R.drawable.onglide).fallback(R.drawable.onglide).error(R.drawable.error).diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter();
                    Glide.with(StudentData.this).load(student.getIdentityImgReverse()).apply(requestOptions2).into(s_ren_z2);
                }
            }
        }
    };

}